package com.yx.properties;


import com.yx.dao.PermissionMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;


@Component
public class PermissionProperties {

    @Resource
    private PermissionMapper permissionMapper;

    public List<String> getForEntity(Object uid){
        return getStrings(uid, permissionMapper);
    }

    static List<String> getStrings(Object uid, PermissionMapper permissionMapper) {
        List<String> permissions = new ArrayList<>();
        Integer id = uid == null ? null : Integer.parseInt(uid.toString());
        List<String> data = permissionMapper.getPermissionByUId(id);
        data.forEach(e -> {
            Iterator<String> permissionsIterator = Arrays.stream(e.split(",")).iterator();
            while (permissionsIterator.hasNext()){
                permissions.add(permissionsIterator.next());
            }
        });
        return permissions;
    }


}
